Haskell: How to compose `not` with a function of arbitrary arity?

Posted by Hynek -Pichi- Vychodil on Stack Overflow See other posts from Stack Overflow or by Hynek -Pichi- Vychodil
Published on 2009-01-05T17:54:03Z Indexed on 2010/03/15 6:09 UTC
Read the original article Hit count: 161

When I have some function of type like

f :: (Ord a) => a -> a -> Bool
f a b = a > b

I should like make function which wrap this function with not.

e.g. make function like this

g :: (Ord a) => a -> a -> Bool
g a b = not $ f a b

I can make combinator like

n f = (\a -> \b -> not $ f a b)

But I don't know how.

*Main> let n f = (\a -> \b -> not $ f a b)
n :: (t -> t1 -> Bool) -> t -> t1 -> Bool
Main> :t n f
n f :: (Ord t) => t -> t -> Bool
*Main> let g = n f
g :: () -> () -> Bool

What am I doing wrong?

And bonus question how I can do this for function with more and lest parameters e.g.

t -> Bool
t -> t1 -> Bool
t -> t1 -> t2 -> Bool
t -> t1 -> t2 -> t3 -> Bool

© Stack Overflow or respective owner

Related posts about haskell

Related posts about composition